package com.server.gateway.utils;


import com.server.common.code.utils.AjaxResult;
import com.server.common.code.utils.GsonUtils;
import com.server.common.code.utils.Result;
import com.server.common.code.utils.ResultUtil;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class MessageUtils {

    /**
     * 发送
     * @author LXC
     * @date 2022/4/25 21:49
     */
    public Mono<Void> sendResponse(ServerWebExchange exchange, Result<?> msg){
        ServerHttpResponse response = exchange.getResponse();
        return response.writeWith(Mono.fromSupplier(() -> 
                response.bufferFactory().wrap(GsonUtils.getGson().toJson(msg).getBytes())));
    }

}
